<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="utf-8" />
        <title>redirectStart and redirectEnd information in same-origin redirect resource timing</title>
        <link rel="author" title="Intel" href="http://www.intel.com/" />
        <link rel="help" href="http://www.w3.org/TR/resource-timing/#performanceresourcetiming"/>
        <script src="/resources/testharness.js"></script>
        <script src="/resources/testharnessreport.js"></script>
        <script src="/webperf/tests/resources/webperftestharness.js"></script>

        <script>
           
            setup({explicit_done: true});
            test_namespace();
            var pageOrigin = "w3c-test.org";

            function onload_test()
            {
                if (!performance || !performance.getEntriesByName)
                {
                    test_true(false, "Performance Timeline interface required by this test is supported!");
                    done();
                    return;                    
                }

                var entry = performance.getEntriesByName(document.getElementById("frameContext").src, "resource")[0];

                test_greater_than(entry.redirectStart, 0, "redirectStart should be greater than 0 in same-origin redirect!");
                test_equals(entry.redirectStart, entry.startTime, "redirectStart should be equal to startTime in same-origin redirect!");
                test_greater_or_equals(entry.redirectEnd, entry.redirectStart, "redirectEnd should be no less than redirectStart in same-origin redirect!");
                test_greater_or_equals(entry.fetchStart, entry.redirectEnd, "fetchStart should be no less than redirectEnd in same-origin redirect!");
                done();
            }
        </script>

    </head>
    <body>
        <h1>Description</h1>
        <p>This test validates the values of the redirectStart/End in resource timing for a same-origin server side resource redirect.</p>
        <iframe id="frameContext" src="" style="width: 250px; height: 250px;"></iframe>
        <script>
            test_equals(document.location.host, pageOrigin, 'Starting document.location.hostname is correct (' + pageOrigin + ')');

            var destUrl = 'http://' + pageOrigin + '/webperf/tests/resources/redirect.php';
            destUrl += '?location=http://' + pageOrigin + "/webperf/tests/resources/blank_page_green.htm";

            var frameContext = document.getElementById("frameContext");
            frameContext.onload = onload_test;
            frameContext.src = destUrl;
        </script>
        <div id="log"></div>
</body>
</html>
